/*
 * @Description: 材质
 * @Author: 张正兴
 * @LastEditors: 张正兴
 * @Date: 2022-06-16 17:15:17
 * @LastEditTime: 2022-06-17 17:58:47
 */
import * as THREE from 'three';

export function physicalMaterial () {
  // 环境贴图
  const loader = new THREE.CubeTextureLoader();
  loader.setPath('/img/');
  const textureCube = loader.load(['01.jpg', '01.jpg', '01.jpg', '01.jpg', '01.jpg', '01.jpg']);
  
  // 开启立方体折射
  textureCube.mapping = THREE.CubeRefractionMapping;

  // 基础材质
  let textureLoader = new THREE.TextureLoader();
  let diffuseReflection = textureLoader.load("/img/01.jpg");
  let normal = textureLoader.load("/img/02.jpg");
  let bump = textureLoader.load("/img/03.jpg");
  let dirt = textureLoader.load("/img/04.jpg");

  // 该材质是真实材质无法模拟透明效果
  const material = new THREE.MeshStandardMaterial();

  // 漫反射
  material.map = diffuseReflection;

  // 法线
  material.normalMap = normal;

  // 凹凸
  material.bumpMap = bump;

  // 粗糙
  material.roughness = 0.2
  material.roughnessMap = dirt

  // 环境贴图
  material.envMap = textureCube
  // reflectivity: 0.1,

  // 金属
  // material.metalness = 0.5;
  material.metalnessMap = dirt

  //自发光
  // material.emissive = new THREE.Color( 0xff0000 );
  // material.emissiveMap = Texture
  // material.emissiveIntensity = 0.2 //发光强度

  // 不透明度
  // material.transparent = true;
  // material.opacity = 0.5

  return material;
}